﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GoodMan.Engine.ExServer.WorkPool.WorkHandle.Email;
using GoodMan.Engine.ExServer.WorkPool.WorkHandle.CommonWork;

namespace GoodMan.Engine.ExServer.WorkPool
{
    internal class WorkFactory<T>
    {
        static Dictionary<WorkType, KeyValuePair<IWorkHandle<T>, Type>> dict = new Dictionary<WorkType, KeyValuePair<IWorkHandle<T>, Type>>();
        static WorkFactory()
        {
            //dict.Add(WorkType.email_for_register,
            //    new KeyValuePair<IWorkHandle<T>, Type>(
            //        new EmailForRegisterHandle<T>(),
            //        typeof(AccountEmail)));
            //dict.Add(WorkType.email_for_resetpassword,
            //    new KeyValuePair<IWorkHandle<T>, Type>(
            //        new EmailForResetPwdHandle<T>(),
            //        typeof(AccountEmail)));
            //dict.Add(WorkType.email_for_inviteexpert_notity,
            //    new KeyValuePair<IWorkHandle<T>, Type>(
            //        new EmailForInviteExpertNotityHandle<T>(),
            //        typeof(InviteForJournalNotityEmail)));
            //dict.Add(WorkType.email_for_welcomeExpert,
            //    new KeyValuePair<IWorkHandle<T>, Type>(
            //        new EmailForWelcomeExpertHandle<T>(),
            //        typeof(WelcomeForExpertEmail)));
            //dict.Add(WorkType.email_for_invitereviser_notity,
            //    new KeyValuePair<IWorkHandle<T>, Type>(
            //        new EmailForInviteReviserNotityHandle<T>(),
            //        typeof(InviteForJournalNotityEmail)));
            //dict.Add(WorkType.email_for_jobnotice,
            //    new KeyValuePair<IWorkHandle<T>, Type>(
            //        new EmailForJobNotityHandle<T>(),
            //        typeof(JobNotityEmail)));
            //dict.Add(WorkType.email_for_manuscriptcheck,
            //    new KeyValuePair<IWorkHandle<T>, Type>(
            //        new EmailForManuscriptCheckHandle<T>(),
            //        typeof(ManuscriptCheckEmail)));
            //dict.Add(WorkType.email_for_examinejobdistribution,
            //    new KeyValuePair<IWorkHandle<T>, Type>(
            //        new EmailForExamineJobDistributionHandle<T>(),
            //        typeof(ZhuanShenJobEmail)));
            //dict.Add(WorkType.email_for_urgeexamine,
            //    new KeyValuePair<IWorkHandle<T>, Type>(
            //        new EmailForUrgeExamineHandle<T>(),
            //        typeof(ZhuanShenJobEmail)));
            dict.Add(WorkType.email_for_normalnotify,
                new KeyValuePair<IWorkHandle<T>, Type>(
                    new EmailForNormalNotifyHandle<T>(),
                    typeof(NormalNotifyEmail)));
            //dict.Add(WorkType.email_for_publication,
            //     new KeyValuePair<IWorkHandle<T>, Type>(
            //        new EmailForPublicationHandle<T>(),
            //        typeof(PublicationEmail)));
        }
        private static IWorkHandle<T> GetHandleWithParam(WorkType type, T context)
        {
            var item = dict[type];
            if (item.Value == typeof(T))
            {
                return item.Key as IWorkHandle<T>;
            }
            return null;
        }
        public static IWorkHandle<T> GetHandle(WorkType type, T context)
        {
            return GetHandleWithParam(type, context);
        }
    }
}
